Generalizing Sticky PDMP

PDMP
Author

司馬 博文

Published

5/20/2025

Modified

5/22/2025

using PlotlyJS

using Plots

# ① PlotlyJS バックエンドに切り替え
plotlyjs()

# 格子生成
us = collect(-1.0:0.05:1.0)
vs = collect(-1.0:0.05:1.0)

# 平面を Mesh3d でプロットする関数
function plane_mesh(xs, ys, zs; col)
    PlotlyJS.mesh3d(x=xs, y=ys, z=zs, opacity=0.5, color=col, showscale=false)
end

# 各平面の座標配列を作成
x1 = hcat([[u,u,v] for u in us, v in vs]...)
x2 = hcat([[v,u,u] for u in us, v in vs]...)
x3 = hcat([[u,v,u] for u in us, v in vs]...)
using PlotlyJS

# パラメータ格子
us = collect(-1.0:0.05:1.0)
vs = collect(-1.0:0.05:1.0)
m, n = length(us), length(vs)

# 頂点リスト(flatten した順序で)
x = Float64[]
y = Float64[]
z = Float64[]
for u in us, v in vs
    push!(x, u); push!(y, u); push!(z, v)   # plane x=y
end

# 三角形フェイスを作成
i = Int[]
j = Int[]
k = Int[]
for ii in 1:m-1
    for jj in 1:n-1
        p1 = (ii-1)*n + jj
        p2 = ii*n       + jj
        p3 = (ii-1)*n + jj+1
        p4 = ii*n       + jj+1
        # 2 つの三角形に分割
        push!(i, p1-1); push!(j, p2-1); push!(k, p3-1)
        push!(i, p2-1); push!(j, p4-1); push!(k, p3-1)
    end
end

trace = PlotlyJS.mesh3d(
    x=x, y=y, z=z,
    i=i, j=j, k=k,                # ★自前の分割インデックス
    opacity=0.5, color="red",
    showscale=false
)
mesh3d with fields color, i, j, k, opacity, showscale, type, x, y, and z
using PlotlyJS, PlotlyBase

using Plots
plotlyjs()

# (1) プロットを作成
plt = PlotlyJS.Plot(
    [
      trace,
      plane_mesh(x2[1,:], x2[2,:], x2[3,:], col="green"),
      plane_mesh(x3[1,:], x3[2,:], x3[3,:], col="blue"),
    ],
    Layout(
      scene = attr(
        xaxis_title="x", yaxis_title="y", zaxis_title="z"
      )
    )
)

io = IOBuffer()
PlotlyBase.to_html(io, plt, full_html=false)
HTML(read(io, String))  # Quartoはこの生HTMLをそのまま出力に埋め込みます
using Plots
plotlyjs()                 # プロットバックエンドにPlotlyJSを指定
Plots.plot(plt)   # 3次元メッシュもOK
plt